<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>分店退货  总店财务审核表</title>
<link rel="stylesheet" href="../../res/mln/layui.css" media="all">
<style type="text/css">

#anniu{
    	position: relative;
    	left:950px;
    	top:-30px;
    }
body {
	margin: 10px;
}

.demo-carousel {
	height: 300px;
	line-height: 300px;
	text-align: center;
}

.demoTable {
	z-index: 10px;
}

#addReload {
	position: absolute;
	top: 0%;
	z-index: 100px;
	background: rgb(0, 0, 0, 0.9);
	width: 100%;
	height: 100%;
	display: none;
}

#addOperation {
	position: absolute;
	left: 30%;
	top: 15%;
	width: 40%;
	background: white;
}
</style>
</head>
<body>
	<div class="demoTable">
		搜索关键字：
		<div class="layui-inline" >
			<input class="layui-input" name="id" id="demoReload"
				autocomplete="off">
		</div>
		
		时间：
		<div class="layui-input-inline">
      	  	<input name="date" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
      	——<div class="layui-input-inline">
      	  	<input name="date" id="date1" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input" type="text">
      	</div>
		<button class="layui-btn" data-type="reload">搜索</button>
		<table class="layui-hide" id="zdCaiWuAudit" lay-filter="demo"></table>
	</div>
	<div id="addReload">
 		<div id="addOperation">
		 	<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
			  <legend>审核信息填写</legend>
			</fieldset>
			<form class="layui-form" id="shForm" action="../../audit/zdCaiWuAudit.action" method="post"  >
			
			  <div class="layui-form-item">
			    <label class="layui-form-label">审核部门</label>
			    <div class="layui-input-block">
			      <input type="hidden" name="pwId" id="pwId">
			      <input type="hidden" name="auditSection" value="总店财务部门">
			      <input type="text" maxlength="20" lay-verify="required" value="总店财务部门" autocomplete="off" class="layui-input layui-disabled" disabled style="width:280px;">
			    </div>
			  </div>
			  <div class="layui-form-item">
			    <label class="layui-form-label">订单名称</label>
			    <div class="layui-input-block">
			      <input type="hidden"  value="8" name="fdPoState">
			      <input type="text" name="roleCode" maxlength="20" value="分店退货订单"  autocomplete="off" class="layui-input layui-disabled" disabled style="width:280px;">
			    </div>
			  </div>
			  <div class="layui-form-item">
			    <label class="layui-form-label">是否通过</label>
			    <div class="layui-input-block" style="width:200px;">
			       <select name="auditPass"  lay-verify="required" lay-filter="isvas" lay-search="" id="isvas">
			       	  <option value="1">是</option>
			          <option value="0">否</option>
			        </select>
			    </div>
			  </div>
			  
			  
			   <div class="layui-form-item layui-form-text" id="auditCause">
			    <label class="layui-form-label">审核意见</label>
				    <div class="layui-input-block">
				      <textarea placeholder="请输入内容" lay-verify="required" maxlength="20" name="auditCause" class="layui-textarea"></textarea>
				    </div>
			  </div>
			  
			  
			  <div class="layui-form-item">
			    <div class="layui-input-block">
			      <input type="submit" class="layui-btn" lay-submit="" lay-filter="roleAdd" value="提交">
			      <button id="closeAdd" type="reset" class="layui-btn layui-btn-primary" >取消</button>
			    </div>
			  </div>
		 </form>
	 </div>
 </div>
 
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="detail" >查看详情</a>
{{# if(d.fdPoState=="分店财务审核成功.等待总店财务审核"){ }}
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="zdcwsh">审核</a>
	{{# } else if(d.fdPoState==1){}}
	{{# }else if(d.fdPoState==0){}}
	{{# } }}
</script>



<script type="text/html" id="salesReturnQuantity">
	<div class="layui-inline">
	    <input class="layui-input input" name="{{ d.fdPodId}}" id="demoReload" autocomplete="off" style="height:30px" onkeyup="num(this);" maxlength="5" required >
		<input class="layui-input" type="hidden" id="{{ d.fdPodId}}">
	 </div>
</script>


<script src="../../res/js/jquery-1.10.2.js"></script>
<script src="../../res/js/layui-xtree.js"></script>
<script src="../../layui/layui.js"></script>
<script src="../../res/js/base.js"></script>
<script type="text/javascript" src="../../res/mln/getUrlParam.js"></script>


<script>
var str = "";
layui.use(['form','laydate', 'laypage', 'layer', 'table', 'upload', 'element','tree'], function(){
  var form = layui.form
  ,laydate = layui.laydate //日期
  ,laypage = layui.laypage //分页
  ,layer = layui.layer //弹层
  ,table = layui.table //表格
  ,upload = layui.upload //上传
  ,element = layui.element; //元素操作
  var path=getRootPath();
	//日期
	  laydate.render({
		    elem: '#date'
	  });
	  laydate.render({
		    elem: '#date1'
	  });
	  
	 
  
  //监听Tab切换
  element.on('tab(demo)', function(data){
    layer.msg('切换了：'+ this.innerHTML);
    console.log(data);
  });
  
  /*  //如果否 出现审核意见
  form.on("select(isvas)",function(){
	  if($("#isvas").val()==0){
		  $("#auditCause").html('<label class="layui-form-label">不通过原因</label>'+
				    '<div class="layui-input-block">'+
				      '<textarea placeholder="请输入内容" maxlength="20" name="auditCause" class="layui-textarea"></textarea>'+
				    '</div>');
	  }else{
		  $("#auditCause").html("");
	  }
	  
  }); */
  
  
  //是否 都出现审核意见
  form.on("select(isvas)",function(){
	  if($("#isvas").val()==0){
		  $("#auditCause").attr('lay-verify','');
	  }else{
		  $("#auditCause").attr("lay-verify","required");
	  }
	  
  });
  
  //执行一个 table 实例
  table.render({
     elem: '#zdCaiWuAudit'
    ,async: false
    ,height: 474
    ,url: path+'FdPurchase/findAllZdCwsh.action' //数据接口
    ,page: true //开启分页
    ,method:'post'
    ,cols: [[ //表头
       {field: 'fdSunnum', title: '采购总数量', width:120,sort: true}
      ,{field: 'fdSumprice', title: '采购总价格', width:120,sort: true}
      ,{field: 'fdPoTimess', title: '采购时间', width:180,sort: true}
      ,{field: 'fdPoPerson', title: '采购人员', width:120}
      ,{field: 'fdPoState', title: '采购状态', width:100}
      ,{field: 'fdNumber', title: '批次号', width:130}
      ,{fixed: 'right',title: '操作', width: 265, align:'center', toolbar: '#barDemo'}
   
    ]]
  	,id: 'testReload'
	,done: function(res, curr, count){
  		str = table.cache.testReload;
  	  }
  });
  
  //监听工具条
  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
    var data = obj.data //获得当前行数据
    ,layEvent = obj.event; //获得 lay-event 对应的值
    var fdPoId = data.fdPoId;
    if(layEvent === 'del'){
      var reId=data.reId;
      layer.confirm('确认删除？', function(index){
        obj.del(); //删除对应行（tr）的DOM结构
        layer.close(index);
        //使用jquery的ajax方式向后台提交数据
		var url = path+"salesReturn/deleteReId.action";
		var data={reId:reId};
			$.post(url,data,function(data){
				
				if(data=="ok"){
					layer.msg('删除成功', {
						  icon: 1,
						  time: 1000 //1秒关闭（如果不配置，默认是3秒）
						}, function(){
						  
					});
				}
			});
      	});
    } else if(layEvent === 'edit'){
	      
	      $("#memberName").val(data.memberName);
	      
	      $("#memberNumber").val(data.memberNumber);
	      $("#menmberPwd").val(data.menmberPwd);
	      $("#img_urlTwo").val(data.memberImage);
	      $("#demoTow").attr("src",path+data.memberImage); 
	      $("#memberId").val(data.memberId);
	      
	      var m=$("#isva").children().next();
	      var n=$("#isva").children();
	      
	      if(m.val()==data.memberSort){      
	         m.attr("selected",true);
	      }else{
	    	 n.attr("selected",true);
	      }
	      form.render("select");
	      $('#updateReload').css('display','block');
		}
    else if(layEvent === 'zdcwsh'){
    	 var id=data.fdPoId;
         $("#pwId").val(id);
         form.render();
         
         $('#addReload').css('display', 'block');
       }else if(layEvent === 'detail'){
      
       	layer.open({
   			title:'分店退货详情'
   			,type:2
   			,area:['59%','70%']
   			,content:[path+'pages/mln/fdPurchaseDetailsh.html?fdPoId='+fdPoId,'yes']
   		});
    }
   });

		//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			var demoReload = $('#demoReload');
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					fdPoPerson : demoReload.val(),
					dateOne: $("#date").val(),
					dateTwo: $("#date1").val(),
				}
			});
		});
		$('#closeAdd').on('click', function() {
			$('#addReload').css('display', 'none');
		});
		
		$('#closeUpdate').on('click', function() {
			
			$('#updateReload').css('display', 'none');
		});
		
		$('#memberAdd').on('click', function() {
			$('#addReload').css('display', 'block');
			
		});
	});
	
	
//限制只能输入数字的正则表达式
function num(obj){
	obj.value = obj.value.replace(/[^\d]/g,"");
	$("#totalMoney").text("0");
	$("#totalNumber").text("0");
	var totalMoney = 0;
	var totalNumber = 0;
	for(var i=0;i<str.length;i++){
		if($(obj).attr("name") == str[i].fdPodId){
			if(obj.value > str[i].fdItemNumber){
				obj.value = str[i].fdItemNumber;
			}
		}
		$("#"+$(obj).attr("name")).val(obj.value);
		//alert(str[i].mxQuantity+obj.value);
		var numOne = $("#"+str[i].fdPodId).val()-0;
		var numTwo = str[i].fdItemNumber-0;
		//如果退货数量小于总数量
		if(numOne <= numTwo){
			totalMoney += str[i].fdPrice * numOne;
			totalNumber += numOne;
		}else{
			//判断药品名称是否等于此ID
			if($(obj).attr("name") == str[i].fdPodId){
				obj.value = str[i].fdItemNumber;
			}
			totalMoney += str[i].fdPrice * numTwo;
			totalNumber += str[i].fdItemNumber;
		}
	};
	$("#totalMoney").text(totalMoney);
	$("#totalNumber").text(totalNumber);
}

</script>
<div><h3 style="color:#c2c2c2">总计:<span id="totalMoney">0</span>元</h3><h3 style="color:#c2c2c2" >总数量:<span id="totalNumber">0</span>件</h3><button class="layui-btn layui-btn-radius" id="anniu">立即提交</button></div>
</body>
</html>